#include <bits/stdc++.h>
using namespace std;
int t,n,a[10005],f[10005],v,sum;
int main()
{
    freopen ("color.in","r",stdin);
    freopen ("color.out","w",stdout);
    cin>>t;
    for (int j=1;j<=t;j++)
    {
        cin>>n;
        for (int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        for (int i=1;i<=v;i++)
        {
            f[i]=0;
        }
        v=0;
        sum=0;
        for (int i=1;i<=n;i++)
        {
            if (a[i]!=a[i-1])
            {
                f[++v]++;
            }
            else
            {
                f[v]++;
                if (f[v]>=2)
                {
                    sum+=a[i];
                }
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}
